export default {
  namespaced: true,
  // 状态清单
  state: () => ({
    // 0-正式 / 1-测试
    model: '',
    title: '',
    url: ''
  }),
  // 动作清单
  actions: {
    // 初始化参数
    init({ commit }, params) {
      const model = localStorage.getItem("setting.model")
      if (model === '' || model === null) {
        localStorage.setItem("setting.model", '0')
        localStorage.setItem("setting.title", '导萃门诊管理系统')
        localStorage.setItem("setting.url", 'http://123.178.235.113:12088/')
      }
    },
    // 设置参数
    set({ commit }, params) {
      commit('setModel', params.model)
      commit('setTitle', params.title)
      commit('setUrl', params.url)
    },
    // 清除缓存
    clear({ commit }) {
      /*
      commit('setModel', '')
      commit('setTitle', '')
      commit('setUrl', '')
      localStorage.removeItem('setting.model')
      localStorage.removeItem('setting.title')
      localStorage.removeItem('setting.url')
      */
    }
  },
  // 设值
  mutations: {
    // 设置模式
    setModel(state, model) {
      localStorage.setItem('setting.model', model)
      state.model = model
    },
    // 设置模式
    setTitle(state, title) {
      localStorage.setItem('setting.title', title)
      state.title = title
    },
    // 设置模式
    setUrl(state, url) {
      localStorage.setItem('setting.url', url)
      state.url = url
    }
  },
  // 取值
  getters: {
    // 获取模式
    getModel(state) {
      if (state.model === '') {
        state.model = localStorage.getItem('setting.model')
      }
      return state.model
    },
    // 获取标题
    getTitle(state) {
      if (state.title === '') {
        state.title = localStorage.getItem('setting.title')
      }
      return state.title
    },
    // 获取URL
    getUrl(state) {
      if (state.url === '') {
        state.url = localStorage.getItem('setting.url')
      }
      return state.url
    }
  }
}
